<?php
namespace app\common\model;
use x\Xbase;
class Patch extends Xbase
{

  //获取碎片数据
  public function getData($uuid=[]){
    $uuid = !is_array($uuid) ? [$uuid] : $uuid;
    $map = [];
    if(!empty($uuid)){
      $map[] = ['and','uuid', 'in', $uuid];
    }
    $w = where($map);
    $rs = $this->db->query("select id from patch_cat {$w[0]}",$w[1]);
    $ids = [];
    foreach($rs as $v){
      $ids[] = $v['id'];
    }
    if($ids){
      $map = [['and', 'a.cat_id', 'in', $ids]];
      $rs = $this->db->query("select a.type,a.content,b.uuid from patch a left join patch_cat b on a.cat_id=b.id {$w[0]} order by a.sort desc,a.id desc",$w[1]);
      $temp = [];
      foreach($rs as $v){
        if(!isset($temp[$v['uuid']])) $temp[$v['uuid']] = [];
        $temp[$v['uuid']][] = $v['type'] ? pic($v['content']) : $v['content'];
      }
      return $temp;
    }
    return [];
  }
}
